﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Diagnostics;

namespace MyDemos.Demos
{
    public partial class test : PhoneApplicationPage
    {
        public test ()
        {
            InitializeComponent ();
            Door a = new Door ();
            Sensor b = new Sensor ();
            a.DoorOpen += b.DoorIsOpening;

            a.Open ();

        }


        class Door
        {
            public delegate void DoorOpenHandler(object sender, DoorOpenArg e);
            public event DoorOpenHandler DoorOpen;

            public class DoorOpenArg : EventArgs
            {
            }

            public virtual void OnDoorOpen (DoorOpenArg e)
            {
                DoorOpen (this,e);
            }

            public void Open ()
            {
                if (DoorOpen != null)
                {
                    OnDoorOpen (new DoorOpenArg());
                }
            }
        }

        class Sensor
        {
            public void DoorIsOpening(object sender, Door.DoorOpenArg e)
            {
                Debug.WriteLine ("門開了");
            }
        }
    }
}